package com.richpay.basejava.base04;

import java.util.Scanner;

public class WhileDemo01{
    public static void main(String [] args){
        int count=0;//计数器，输出5次则退出程序
        Scanner scanner=new Scanner(System.in);
        String account=inPutAccount(scanner);
        System.out.println("请输入您的密码:");
        String pwd=scanner.next();
        while (!(pwd.equals("0000")&&account.equals("01"))) {
            count++;
            if(count<5) {
                System.out.println("您账号或密码有误,请重新输入,还有" + (5 - count) + "次尝试机会!");
                account=inPutAccount(scanner);
                System.out.println("请输入您的密码");
                pwd=scanner.next();
            }else {
                System.out.println("您的账号被锁定,请联系管理员!\n程序结束!");
               return;
            }
        }
        System.out.println("欢迎"+account+",登录成功!\n程序结束!");
    }

    /**
     * @param scanner
     * @return 返回账号
     */
    private static String inPutAccount(Scanner scanner){
        System.out.println("请输入您的账号:");
        String account=scanner.next();
        while (account.length()<2){
            System.out.println("账号必须大于2位,请重新输入您的账号:");
            account=scanner.next();
        }
        return account;
    }
}